calendar: Handle invalid dates
authorEmmanuele Bassi <ebassi@gnome.org>
Fri, 2 Jan 2015 23:05:29 +0000 (23:05 +0000)
committerEmmanuele Bassi <ebassi@gnome.org>
Fri, 2 Jan 2015 23:15:55 +0000 (23:15 +0000)
GtkCalendar can have an invalid date — mostly at initialization. This
means that GDateTime construction may fail. We need to handle that case
gracefully, like the old code did.

This fixes the `notify` test suite, which started failing with:

/Notification/GtkCalendar:
GLib-CRITICAL **: g_date_time_get_day_of_week: assertion 'datetime != NULL' failed

inside the Continuous builder.

gtk/gtkcalendar.c

index 3985a7d42e6358fe0ecf1e510b3f08b7601ee044..b4ef54307bede154060c6a4574a16e2775807081 100644 (file)
@@ -108,6 +108,9 @@ day_of_week (guint year, guint mm, guint dd)
   guint days;
 
   dt = g_date_time_new_local (year, mm, dd, 1, 1, 1);
+  if (dt == NULL)
+    return 0;
+
   days = g_date_time_get_day_of_week (dt);
   g_date_time_unref (dt);
 
@@ -121,6 +124,9 @@ week_of_year (guint year, guint mm, guint dd)
   guint week;
 
   dt = g_date_time_new_local (year, mm, dd, 1, 1, 1);
+  if (dt == NULL)
+    return 1;
+
   week = g_date_time_get_week_of_year (dt);
   g_date_time_unref (dt);